package com.fanfanwang.ffw.app;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;

import android.annotation.SuppressLint;
import android.os.Environment;
import android.text.TextUtils;


public class AppConstant {
	public final static String HTTP_HEAD = "http://182.92.173.95/";
	public final static String HTTP_TEXT_IMG_READY_URL = HTTP_HEAD+"apiserver/product.php?flag=ready&id=";
	public final static String HTTP_TEXT_IMG_CLOWN_URL = HTTP_HEAD+"apiserver/product.php?flag=clown&id=";
	public final static String HTTP_TEXT_IMG_YIFENQIAN_URL = HTTP_HEAD+"apiserver/product.php?flag=yifenqian&id=";
	/**产品支付通知url*/
	public final static String _URL_ALIPAY_SERVER_NOTIFY = HTTP_HEAD+"pay/alipay_server/notify_url.php";
	/**auction珍品拍卖支付通知url*/
	public final static String _URL_ALIPAY_SERVER_AUCTION_NOTIFY = HTTP_HEAD+"pay/alipay_server_auction/notify_url.php";
	/**live活支付通知url*/
	public final static String _URL_ALIPAY_SERVER_LIVE_NOTIFY = HTTP_HEAD+"pay/alipay_server_live/notify_url.php";
	/**支付通知url*/
	public final static String _URL_ALIPAY_SERVER_RECHARGE_NOTIFY = HTTP_HEAD+"pay/alipay_server_recharge/notify_url.php";
	public static String imei;
	public static String headimg;
	public static String user_id;
	public static String username;
	public static String user_nickName;
	public static String newVersion;
	public static String isFirstLogin = "0";
	public static boolean isFromWelcom = false;
	public static boolean isFromFocus = false;
	public static boolean isWeixin = true;// 
	public static boolean isShared = true;// 
	private static String sdCardPath = Environment.getExternalStorageDirectory().toString();
	
	@SuppressLint("SdCardPath")
	public static final String PATH = sdCardPath + "/huoqianer/";
	public static final String IMAGE_PATH = sdCardPath + "/huoqianer/image/";
	public static final String IMAGE_SMALL_PATH = sdCardPath + "/huoqianer/small_image/";
	public static final String TEXT_CHCHE = sdCardPath + "/huoqianer/cache/";
	public static final String LOG_CHCHE = sdCardPath + "/huoqianer/log/";

	@SuppressLint("SdCardPath")
	public static final String RECORD_PATH = sdCardPath + "/huoqianer/record/";

//	public static IntegralBean integralBean = new IntegralBean();
//	public static ArrayList<CityNetBean> cityNetBeans = new ArrayList<CityNetBean>();
	/**
	 * ΢��key
	 */
	public static final String WEIBO_SINA_KEY = "2168238665";// 正式2168238665
	public static final String WEIBO_SINA_SECRET = "ef8b3892881e31e04fbbc85f07f9ff01";// ef8b3892881e31e04fbbc85f07f9ff01
	public static final String WEIBO_SINA_CALLBACKURL = "http://szicity.com";// szicity.com
	/**每次加载数量*/
	public static final int LOAD_SIZE = 10;

	
	public static boolean isOpenShock;//是否开启振动
	public static boolean isOpenSound;//是否开启声音
	public static boolean isReceiveNewTips;//是否接收新消息提醒
	
	// 手机电话本查询返回值
	public static final int PhoneBookSearchSuccess = 1001;
	public static final int PhoneBookSearchErr = 2001;
	
	// MyLetterListView用缓存
	public static HashMap<Integer, String> placeint = new HashMap<Integer, String>();
	public static HashMap<String, Integer> placestr = new HashMap<String, Integer>();
	public static String preLetterStr = "";
	public static String currentLetterStr = "";
	
	public static int choposition1;
	public static int choposition2;
	public static int firstVisibleItem;
	public static int maxitemcount;
	
	public static String isAsk;
	
	public static boolean isUpdateCity = false;
	public static boolean isHuoerUpdateCity = false;
	/**
	 * 是否保存活钱列表至文件
	 */
	public static boolean isSaveFileMoney = true;
	/**
	 * 是否保存活列表至文件
	 */
	public static boolean isSaveFileHuoer = true;
	public static HashMap<String, Integer> getHashMap() {
		String[] ary = currentLetterStr.split(",");
		HashMap<String, Integer> hashmap = new HashMap<String, Integer>();
		for (int i = 1; i < ary.length; i++) {
			hashmap.put(ary[i], i);
		}
		return hashmap;
	};
	
			
//	public static ArrayList<PicBean> currentPicBeans = new ArrayList<PicBean>();
//	public static ArrayList<PicBean> list;
	/**活钱内容型*/
	public static final String TYPE_HUOMONEY_CONTENT = "content";
	/**活钱产品型*/
	public static final String TYPE_HUOMONEY_PRODUCT = "product";
	/**活宝产品型*/
	public static final String TYPE_HUOBAO_PRODUCT = "product";
	/**活宝团购型*/
	public static final String TYPE_HUOBAO_GROUP = "group";
	/**活宝一元抢购型*/
	public static final String TYPE_HUOBAO_ONEYUAN = "oneyuan";
	/**活宝秒杀型*/
	public static final String TYPE_HUOBAO_SECKILL = "seckill";
	/**活宝限时抢购型*/
	public static final String TYPE_HUOBAO_FLASHSALE = "flashsale";
	/**活宝珍品拍卖型*/
	public static final String TYPE_HUOBAO_AUCTION = "auction";
	
	/**首页一分钱专享*/
	public static final String TYPE_HOME_APENNY = "apenny";
	/**首页聊活*/
	public static final String TYPE_HOME_LIAO = "liaoliao";
	/**首页悦活*/
	public static final String TYPE_HOME_FIND = "find";
	/**首页钱袋*/
	public static final String TYPE_HOME_MONEY = "money";
	/**首页活钱*/
	public static final String TYPE_HOME_MESSAGEREADY = "messageready";
	/**首页抢活*/
	public static final String TYPE_HOME_ROBLIVE = "roblive";
	/**首页找活*/
	public static final String TYPE_HOME_FINDLIVE = "findlive";
	/**首页活宝*/
	public static final String TYPE_HOME_MESSAGECLOWN = "messageclown";
	/**商品类型 活钱*/
	public static final String PRODUCT_FLAGS_READYS = "readys";
	/**商品类型 活宝*/
	public static final String PRODUCT_FLAGS_CLOWN = "clown";
	/**一分钱 活宝*/
	public static final String PRODUCT_NEW_USER = "apenny";
	
	
	
	/**--------------------------------------------------------新消息通知类型--------------------------------------*/
	/**
	 * 获奖者通知类型
	 */
	public static final String NOTIFICATION_FLAG_ONEYUAN = "oneyuan";
	/**
	 * 发布者通知类型
	 */
	public static final String NOTIFICATION_FLAG_FBONEYUAN = "fboneyuan";
	/**
	 * 订单变更通知通知类型
	 */
	public static final String NOTIFICATION_FLAG_ORDER = "orders";
	/**
	 * 活变更通知类型
	 */
	public static final String NOTIFICATION_FLAG_LIVE = "live";
	/**
	 * 余额变更通知类型
	 */
	public static final String NOTIFICATION_FLAG_TIXIAN = "tixian";
	
	
	/**
	 * 生成保存的文件名
	 * 
	 * @param time
	 * @return
	 */
	public static String getNewFilePath(String time, String folder, int random) {
		if (!TextUtils.isEmpty(folder)) {
			File file = new File(folder);
			if (!file.exists()) {
				file.mkdirs();
			}
		}

		StringBuffer path = new StringBuffer();
		path.append(folder);
		path.append("IMG_");
		try {
//			path.append(TimeUtils.getDateYYYYMMDD(time) + "_");
		} catch (Exception e) {
			e.printStackTrace();
		}
		path.append(random);
		path.append(".jpg");
		return path.toString();
	}


	public static String getNewFilePathnew(String folder) {
		if (!TextUtils.isEmpty(folder)) {
			File file = new File(folder);
			if (!file.exists()) {
				file.mkdirs();
			}
		}

		StringBuffer path = new StringBuffer();
		path.append(folder);

		return path.toString();
	}

	public static String getNewFilePathByPhotoId(String folder, String photo_id) {
		if (!TextUtils.isEmpty(folder)) {
			File file = new File(folder);
			if (!file.exists()) {
				file.mkdirs();
			}
		}

		StringBuffer path = new StringBuffer();
		path.append(folder);
		path.append(photo_id);
		path.append(".jpg");
		return path.toString();
	}

	public static int random6() {
		int[] array = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
		Random rand = new Random();
		for (int i = 9; i > 1; i--) {
			int index = rand.nextInt(i);
			int tmp = array[index];
			array[index] = array[i - 1];
			array[i - 1] = tmp;
		}
		int result = 0;
		for (int i = 0; i < 6; i++)
			result = result * 10 + array[i];
		return result;
	}


	public static long earliest = -1l;
	public final static String system = "android";

	public static void clear() {
		imei = null;
		user_id = null;
	}
	/**url解码*/
	public static String URLDecoderString(String t){
		if(TextUtils.isEmpty(t)){
			return "";
		}
		try {
			String str = URLDecoder.decode(t, "UTF-8");
			return str;
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "";
	}
	
	/**url编码 上传的时候调用*/
	public static String URLEncoderString(String s){
		try {
			String str = URLEncoder.encode(s, "UTF-8");
			return str;
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	
	public static String getHttpUrl(String imgurl){
		if(TextUtils.isEmpty(imgurl)){
			return "";
		}
		String httpImgUrl = imgurl;
		if(imgurl.startsWith("http://")){
			httpImgUrl = imgurl;
		}else {
			httpImgUrl = HTTP_HEAD + imgurl;
		}
		return httpImgUrl;
		
	}

}
